package com;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.sql.Driver;

public class Main {
    public static void main1(String[] args) throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();

        webDriver.get("https://www.baidu.com/");
        // 定位到搜索框，并且输入 id
        webDriver.findElement(By.id("kw")).sendKeys("test");
        Thread.sleep(2000);
        // 清空搜索框中的内容，即删除 test
        webDriver.findElement(By.id("kw")).clear();
        // 定位到搜索框，并且输入selenium
        webDriver.findElement(By.id("kw")).sendKeys("selenium");
        // 提交
        webDriver.findElement(By.id("su")).submit();


    }

    public static void main2(String[] args) {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.baidu.com/");
        // 获取文本信息
        String text = webDriver.findElement(By.xpath("//*[@id=\"s-top-left\"]/a[1]")).getText();
        System.out.println(text);
    }

    public static void main3(String[] args) throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.baidu.com/");
        // 窗口最大化
        webDriver.manage().window().maximize();
        Thread.sleep(2000);
        // 全屏
        webDriver.manage().window().fullscreen();
        Thread.sleep(2000);

    }
    public static void main4(String[] args) throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.id("kw")).sendKeys("selenium");
        webDriver.findElement(By.id("su")).click();
        Thread.sleep(3000);
        // 刷新
        webDriver.navigate().refresh();
        // 后退
        webDriver.navigate().back();
        Thread.sleep(3000);
        // 前进
        webDriver.navigate().forward();
    }

    public static void main(String[] args) {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.id("kw")).sendKeys("selenium");
        webDriver.findElement(By.id("su")).click();

    }
}